/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opk.Solver;

import java.awt.Point;

/**
 *
 * @author Dawid
 */
public class PointsSortComparator implements java.util.Comparator
{

    private Point pointWithMinY;

    PointsSortComparator(Point pointWithMinY)
    {
        this.pointWithMinY = pointWithMinY;
    }

    public int compare(Object sortedPoint1, Object sortedPoint2)
    {
        double result = ((SortedPoint) sortedPoint1).getAlfaValue() - ((SortedPoint) sortedPoint2).getAlfaValue();

        if (result == 0)    //TODO sprawdzic czy lapie wszystko (double)
        {
            double distance1 = pointWithMinY.distance((SortedPoint) sortedPoint1);
            double distance2 = pointWithMinY.distance((SortedPoint) sortedPoint2);
            if (distance1 == distance2)
            {
             //   System.out.println("dwa identyczne punkty na liscie w grahamie");
                return 0;
            }
            else
            {
                return (int) (distance2 - distance1);
            }
        }
        else if (result > 0)
        {
            return 1;
        }
        else
        {
            return -1;
        }
    }
}
